<?php
/**
 * Created by PhpStorm.
 * User: THINK
 * Date: 2017/8/25
 * Time: 17:35
 */
namespace Admin\Controller;
use Think\Controller;
class PersonalController extends Controller {
    public function index(){

        $User = M('user');

        $username = $_SESSION['username'];

        $list = $User->where("username = '$username'")->find();

        $this->assign('arr',$list);

        $this->display();

    }

    public function editUser(){

        $num = I('post.');

        $User = M('user');

        $User->save($num);

        $this->success('修改成功','index',3);
    }

    public function edit(){

        $this->display();

    }

    public function editPwd(){

        $num = I('post.');

        $User = M('user');

        $username = $_SESSION['username'];

        $list = $User->where("username = '$username'")->find();

        if(md5(md5($num['oldpassword']))!=$list['password']){

            echo "<script>alert('旧密码不正确！');history.back();</script>";

            exit;

        }

        if($num['rpassword']!=$num['password']){

            echo "<script>alert('新密码两次输入不一致！');history.back();</script>";

        }else{

            $num['password'] = md5(md5($num['password']));

            $User->where("username = '$username'")->save($num);

            $this->success('修改成功','edit',3);

        }

    }

}